import os
import PyPDF2
class ReadPdf:
    def __init__(self,pdf_file):
        base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
        self.pdf_file = os.path.join(base_dir, "file", pdf_file)

    #读取pdf文件
    def load_pdf_rules(self):
        try:
            if not os.path.exists(self.pdf_file):
                return "使用DIP病种目录库标准分组规则"

            with open(self.pdf_file, 'rb') as file:
                pdf_reader = PyPDF2.PdfReader(file)
                text = ""
                for page in pdf_reader.pages:
                    text += page.extract_text() + "\n"
                return text.strip()

        except Exception as e:
            return e.args;